package water.com.Aop;

import water.com.Log.Log;
import water.com.util.WaterSQLGenerator;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;

/**
 * 增强SQL生成器，打印其生成的SQL语句
 */
public class WaterSqlPrintHandler implements InvocationHandler {
    private WaterSQLGenerator<Object> waterSqlGeneratorImp;

    public WaterSqlPrintHandler(WaterSQLGenerator<Object> waterSQLGenerator){
        this.waterSqlGeneratorImp = waterSQLGenerator;
    }
    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        String res = null;
        res = (String)method.invoke(waterSqlGeneratorImp,args);
        Log.getLog().info(res);
        return res;
    }
}
